<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
  <title>天量科技管理后台</title>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width">
  <link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="stylesheet" href="css/templatemo_main.css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body ng-app="app" ng-controller="index">
<div class="navbar navbar-inverse" role="navigation">
  <div class="navbar-header">
    <div class="logo"><h1>天量科技管理后台</h1></div>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
</div>
<div class="template-page-wrapper">
  <div class="navbar-collapse collapse templatemo-sidebar">
    <ul class="templatemo-sidebar-menu">
      <li>
        <form class="navbar-form">
          欢迎您:{{user.name || '访客'}}</span>
        </form>
      </li>
      <li ng-repeat="menu in menus" ng-class="menu.menuclass" ng-click="menuclick(menu)">
        <a ng-click="redi(menu.url)" ng-if="menu.items.length==0"><i ng-class="menu.icon"></i>{{menu.label}}</a>
        <a href="#" ng-if="menu.items.length>0">
          <i ng-class="menu.icon"></i> {{menu.label}} <div class="pull-right"><span class="caret"></span></div>
        </a>
        <ul class="templatemo-submenu" ng-if="menu.items.length>0">
          <li ng-repeat="item in menu.items" ng-click="redi(item.url)"><a href="javascript:void(0)">{{item.label}}</a></li>
        </ul>
      </li>
      <li>
        <a href="#" data-toggle="modal" data-target="#confirmModal"><i class="fa fa-sign-out"></i>退出登录</a>
      </li>
    </ul>
  </div><!--/.navbar-collapse -->

  <div class="templatemo-content-wrapper">
    <div class="templatemo-content">
      <ol class="breadcrumb">
        <li><a ng-click="redi('index.html')" href="javascript:void(0)">首页</a></li>
      </ol>

      <div class="row" ng-if="haserror">
        <div class="alert alert-danger alert-dismissible" role="alert">
          <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <strong>发生异常情况:{{errormessage}}</strong>
        </div>
      </div>

      <div class="panel panel-primary">
        <h4 class="panel-heading">压力支撑位</h4>
        <div class="panel-body">
          <div class="span3">
            <div class="control-group success">
              交易品种代码:<input type="text" class="span3" placeholder="EURUSD" ng-model="symbol" maxlength="8" size="9"/>&nbsp;&nbsp;
              压力支撑位类型<select ng-model="ylzctype" ng-options="y.title for (x, y) in ylzctypes"  ng-change="query(0)"></select>&nbsp;&nbsp;
              压力支撑位级别<select ng-model="level" ng-options="y.title for (x, y) in levels" ng-change="query(0)"></select>&nbsp;&nbsp;
              日期:<input type="text" class="span3" value="" ng-model="thedate"  maxlength="8" size="9"/>&nbsp;&nbsp;
              值:<input type="text" class="span3" ng-model="value" maxlength="8" size="9">&nbsp;&nbsp;
              <input type="hidden" value="86400" ng-model="period">
              <button class="btn btn-mini btn-success" ng-click="query()">搜索</button>
              <button class="btn btn-mini btn-success" ng-click="insert()">新增</button>
            </div>
          </div>
        </div>
        <table class="table table-striped table-hover table-bordered">
          <thead>
          <tr>
            <th>ID</th>
            <th>交易品种</th>
            <th>类型</th>
            <th>值</th>
            <th>位置日期</th>
            <th>时间周期</th>
            <th>级别</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <tr ng-repeat="item in data.content">
            <td>{{ item.id }}</td>
            <td>{{ item.symbol }}</td>
            <td>
              <span ng-if="item.type=='Y'">压力位</span>
              <span ng-if="item.type=='Z'">支撑位</span>
            </td>
            <td>{{ item.value }}</td>
            <td>{{ item.thedate | date: 'yyyyMMdd'}}</td>
            <td>
              <span ng-if="item.period==86400">日级别</span>
              <span ng-if="item.period==3600">1小时级别</span>
              <span ng-if="item.period==900">15分钟级别</span>
              <span ng-if="item.period==300">5分钟级别</span>
            </td>
            <td>{{ item.level  }}级</td>
            <td><img src="images/{{item.status}}.png"></td>
            <td>
              <button type="button" class="btn btn-success" ng-click="redi('ylzc_edit.html?id='+item.id)">编辑</button>
              <button type="button" class="btn btn-warning" ng-if="item.status=='A'" ng-click="disableById(item.id)">停用</button>
              <button type="button" class="btn btn-info" ng-if="item.status=='S'" ng-click="activeById(item.id)">启用</button>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <span ng-show="data.totalElements>0">共找到<font color="red">{{data.totalElements}}</font>条数据,分<font color="red">{{data.totalPages}}</font>页</span>
      <ul class="pagination pull-right">
        <li ng-class="firstclass" ng-show="!data.first"><a href="javascript:void(0)" ng-click="query(0)">&laquo;</a></li>
        <li ng-repeat="p in pages" ng-class="p.currentclass">
          <a ng-click="query(p.i)" href="javascript:void(0)">{{p.i}} <span class="sr-only">(current)</span></a>
        </li>
        <li ng-class="lastclass" ng-show="!data.last"><a href="javascript:void(0)" ng-click="query(data.totalPages-1)">&raquo;</a></li>
      </ul>

    </div>
  </div>

  <!-- Modal -->
  <div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <h4 class="modal-title" id="myModalLabel">确定退出吗</h4>
        </div>
        <div class="modal-footer">
          <a ng-click="logout()" class="btn btn-primary" data-dismiss="modal">确定</a>
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        </div>
      </div>
    </div>
  </div>

  <footer class="templatemo-footer">
    <div class="templatemo-copyright">
      <p>Copyright &copy; 2018 By <a href="http://skyquant.cn" title="天量科技" target="_blank">天量科技</a></p>
    </div>
  </footer>
</div>
</body>

<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/common.js"></script>
<script src="js/templatemo_script.js"></script>
<script type="text/javascript">
  'use strict';
  var app = angular.module('app', []);
  var maxpage = 10;//最多10页
  var ylzctypes = [
      {title:"压力位",value:"Y"},
      {title:"支撑位",value:"Z"}
  ];
  var levels = [
        {title:"全部",value:0},
        {title:"1级",value:1},
        {title:"2级",value:2},
        {title:"3级",value:3},
        {title:"4级",value:4},
        {title:"5级",value:5}
  ];
  app.controller('index', ['$scope', '$http', function ($scope, $http) {

      //每个页面都要有的方法begin
      $scope.init = function(){
        getUser($http,$scope,'压力支撑位','后台参数设置');
      }

      $scope.logout = function(){
        logout($http);
      }

      $scope.menuclick=function(menu){
        changemenuclass($scope,menu);
      }

      $scope.redi=function(url){
          location.href = url;
      }
      //每个页面都要有的方法begin

      //每个页面都需要重写此方法，发生在init之后
      $scope.initAfter = function(){
        $scope.query(0);
      }

      $scope.query = function(page){
        var httpurl = 'quant4j-service/ylzc/list?symbol='+$scope.symbol+"&period="+$scope.period+"&type="+$scope.ylzctype.value+'&level='+$scope.level.value+'&page='+page+'&size='+$scope.size;
        $http.get(httpurl).success(function(data){
            pagecommon($scope,data);
        }).error(function(data,status,headers,config){
            $scope.haserror = true;
            $scope.errormessage = '系统错误'+status;
        });
      }

      $scope.activeById=function(id){
          var httpurl = 'quant4j-service/ylzc/'+id+'/active';
          $scope.updateDB(httpurl,null,'PUT','确定启用'+id+'号压力支撑位吗');
      }
      $scope.disableById=function(id){
          var httpurl = 'quant4j-service/ylzc/'+id+'/disable';
          $scope.updateDB(httpurl,null,'PUT','确定停用'+id+'号压力支撑位吗');
      }
      $scope.insert=function(){
        var httpurl = 'quant4j-service/ylzc';
        if($scope.symbol=="" || $scope.symbol=="undefined"){
            alert("请输入交易品种");
            return;
        }
        if($scope.value=="" || $scope.value=="undefined"){
            alert("请输入压力支撑位的值");
            return;
        }
        if($scope.thedate=="" || $scope.thedate=="undefined"){
            alert("请输入时间");
            return;
        }
        if($scope.thedate.length!=8){
            alert("时间格式不正确");
            return;
        }
        if($scope.level.value<1 || $scope.level.value>5){
            alert("支撑压力位的级别只能在1-5之间");
            return;
        }
        var dataMap = {
            "value":$scope.value,
            "period":$scope.period,
            "level":$scope.level.value,
            "symbol":$scope.symbol,
            "type":$scope.ylzctype.value,
            "thedate":$scope.thedate};
        var r = '确定要新增一个'+$scope.symbol+'的级别为'+$scope.level.value+',值为'+$scope.value+',时间为'+$scope.thedate+'的'+($scope.ylzctype.value=='Y'?'压力':'支撑')+'位吗?';
        $scope.updateDB(httpurl,dataMap,'POST',r);
      }
      $scope.updateDB=function(httpurl,dataMap,m,r){
        var b = true;
        if(r!=null){
            b = confirm(r);
        }
        if(b){
            $http({
                 method:m,
                 url:httpurl,
                 data:dataMap,
                 headers:{'Content-Type': 'application/x-www-form-urlencoded'},
                  transformRequest: function(obj) {
                      var s = [];
                      for(var p in obj){
                          s.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                      }
                      return s.join("&");
                  }
             }).success(function(data){
                 if(data.ok){
                  $scope.query($scope.data.number);
                 }else{
                     alert(data.message);
                 }
             });
        }
      }
      initPage($scope,20,10);
      $scope.symbol = 'EURUSD';
      $scope.ylzctypes = ylzctypes;
      $scope.ylzctype = ylzctypes[0];
      $scope.levels = levels;
      $scope.level = levels[0];
      $scope.thedate = '20180101';
      $scope.value = 1.24;
      $scope.period = 86400;
      $scope.type = 86400;
      $scope.init();
  }]);
</script>
</html>